﻿package fj.site
{
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.external.ExternalInterface;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import com.asual.*;
	
	public class FJSite extends MovieClip
	{
		public var preload:MovieClip;
		public var menu:MovieClip;
		
		private var _model:Model;
		private var _preload:MovieClip;
		
		public function FJSite():void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			_model = Model.getInstance();
			_model.root = this;
			_preload = getChildByName( "preload" ) as MovieClip;
			
			stop();

			if( _model.preload ){
				_model.conteudo = _preload;
				root.loaderInfo.addEventListener( ProgressEvent.PROGRESS, rootProgress );
				root.loaderInfo.addEventListener( Event.COMPLETE, rootComplete );
			}
		}
		private function rootProgress( e:ProgressEvent ):void
		{
			if(currentFrame==2){
				gotoAndStop(1)
			}
			_preload.percent = Math.round( e.bytesLoaded / e.bytesTotal * 100 );
		}
		private function rootComplete( e:Event ):void
		{
			if( _model.deepLinking ){
				SWFAddress.initialize();
				SWFAddress.addEventListener( SWFAddressEvent.INIT, swfAddressInit );
			} else {
				_model.pagina = "Home";
			}
		}
		private function swfAddressInit( e:SWFAddressEvent ):void
		{
			_model.pagina = e.value;
		}
	}
}